package edu.gdkm.iodemo;

import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class FileIODemo {
    public static void main(String[] args) throws IOException {
        File file = new File("./data/scores.csv");
        BufferedReader br = new BufferedReader(new FileReader(file));
        String facebook[] = new String[25000];
        int i = 0;
        String line;
        while ((line = br.readLine()) != null) {
            facebook[i++] = line;
        }
        br.close();
        //按学号查找同学的所有信息，并输出到d盘以该学号命名的txt文件中

        while(true){
            System.out.println("请输入要查找的学号：");
            br = new BufferedReader(new FileReader(file));
            Scanner scanner = new Scanner(System.in);
            String id = scanner.next();
            boolean flag = false;
            long time1 = System.currentTimeMillis();
            for (int j = 0; j < i; j++) {

                if (facebook[j].contains(id)) {
                    flag = true;
                    System.out.println(facebook[j]);
                    break;
                }
//                line = br.readLine();
//                if(line.contains(id)){
//                    flag = true;
//                    System.out.println(line);
//                    break;
//                }
            }
            if(flag){
                System.out.println("查找成功，已输出到D盘以该学号命名的txt文件中");
            }else{
                System.out.println("查找失败，请重新输入");
            }
            long time2= System.currentTimeMillis();
            System.out.println("查询时间：" +(time2-time1)+"ms");
        }

    }
}
